class Solution:
    def countRangeSum(self, nums, lower: int, upper: int) -> int:
        if len(nums) == 0:
            return 0
        re = 0
        dp = [0] * len(nums)
        for i in range(len(nums)):
            dp[i] = nums[i]
            if lower <= dp[i] <= upper:
                re += 1
            for k in range(i):
                sumNum = dp[k] + dp[i]
                dp[k] = sumNum
                if lower <= sumNum <= upper:
                    re += 1
        return re

if __name__ == '__main__':
    so = Solution()
    nums = [-2,5,-1]
    lower = -2
    upper = 2
    r = so.countRangeSum(nums, lower, upper)
    print(r)
